using UnityEngine;
using UnityEditor;
using System.IO;
public static class DataExporter
{
    public static string floder = Application.dataPath+"/export";
    static DataExporter()
    {

    }

    public static void Export()
    {
        var dict = AssetBundleManager.MainBundle.LoadedAssetBundles;
        foreach (var pair in dict)
        {
            var ab = pair.Value.m_AssetBundle;
            var abFloder = Path.Combine(floder, pair.Key);
            if (!Directory.Exists(abFloder))
            {
                Directory.CreateDirectory(abFloder);
            }
            foreach (var name in ab.AllAssetNames())
            {
                var asset = ab.LoadAsset(name);
                if (asset.GetType() != typeof(AssetBundleManifest))
                {
                    Exporter(asset, Path.Combine(abFloder, name));
                }
            }
        }
    }

    public static void Exporter(Object asset, string path, string extension)
    {
        Exporter(asset, path + "." + extension);
    }

    public static void Exporter(Object asset, string path)
    {
        var obj = Object.Instantiate(asset);
        var floder = path.Substring(0, path.LastIndexOf('/') + 1);
        if (!Directory.Exists(floder))
        {
            Directory.CreateDirectory(floder);
        }
        AssetDatabase.CreateAsset(asset, path);
    }
}